﻿using LanguagePolish.EntityModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LanguagePolish
{
    /// <summary>
    /// Содержит глобальную инфу и логику.
    /// </summary>
    public class GlobalModel
    {
        public event EventHandler CollectionsChanged;

        public void SetUserPermissions(User user)
        {
            CurrentUser = user;
            if (user.Teacher != null)
            {
                CanUserAddStudents = user.Teacher.CanAddStudents == true;
            }
            else
            {
                CanUserAddStudents = true;
            }
        }

        public bool IsSeeAll 
        {
            get { return CurrentUser.AccountType.IsSeeAll == true; }
        }

        public bool CanUserAddStudents { get; private set; }

        public User CurrentUser { get; private set; }
        
        private LanguageSchoolEntities context = new LanguageSchoolEntities();

        /// <summary>
        /// Контекст Entity.
        /// </summary>
        public LanguageSchoolEntities EntityContext
        {
            get { return context; }
        }
        
        public void CollectionsHasBeenChanged()
        {
            if (CollectionsChanged != null) 
                CollectionsChanged(this, EventArgs.Empty);
        }
    }
}
